package webapp.mvc.models;

import com.zoowii.jpa_utils.orm.Model;
import webapp.mvc.enums.IntBooleans;
import webapp.mvc.finders.ShopFinder;
import webapp.mvc.utils.IdGenerator;
import webapp.mvc.utils.TimeUtil;

import javax.persistence.*;
import java.sql.Timestamp;

@Entity
@Table(name = "shop")
public class ShopEntity extends Model {
    public static final ShopFinder find = new ShopFinder(String.class, ShopEntity.class);
    private String id = IdGenerator.nextId();
    private String name;
    private String description = "";
    private String logoUrl = "";
    private String categoryId = "";
    private int viewCount = 0;
    private int commentCount = 0;
    private int shopCommentCount = 0;
    private int collectCount = 0;
    private String address = "";
    private String contact = "";
    private float discount = 0;
    private int deleted = IntBooleans.FALSE;
    private String ownerId;
    private Timestamp createTime = TimeUtil.currentTimestamp();
    private Timestamp modifyTime = TimeUtil.currentTimestamp();

    // transient fields
    private ShopCategoryEntity category;
    private int rating = 5;

    @Transient
    public int getRating() {
        return rating;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    @Id
    @Column(name = "id", nullable = false)
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(name = "name", nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "owner_id", nullable = false)
    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    @Column(name = "description", nullable = false)
    @Lob
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Transient
    public ShopCategoryEntity getCategory() {
        return category;
    }

    public void setCategory(ShopCategoryEntity category) {
        this.category = category;
    }

    @Column(name = "contact", nullable = false)
    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    @Column(name = "address", nullable = false)
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Column(name = "shop_comment_count", nullable = false)
    public int getShopCommentCount() {
        return shopCommentCount;
    }

    public void setShopCommentCount(int shopCommentCount) {
        this.shopCommentCount = shopCommentCount;
    }

    @Column(name = "view_count", nullable = false)
    public int getViewCount() {
        return viewCount;
    }

    public void setViewCount(int viewCount) {
        this.viewCount = viewCount;
    }

    @Column(name = "collect_count", nullable = false)
    public int getCollectCount() {
        return collectCount;
    }

    public void setCollectCount(int collectCount) {
        this.collectCount = collectCount;
    }

    @Column(name = "comment_count", nullable = false)
    public int getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(int commentCount) {
        this.commentCount = commentCount;
    }

    @Column(name = "logo_url", nullable = false)
    public String getLogoUrl() {
        return logoUrl;
    }

    public void setLogoUrl(String logoUrl) {
        this.logoUrl = logoUrl;
    }

    @Column(name = "discount", nullable = false)
    public float getDiscount() {
        return discount;
    }

    public void setDiscount(float discount) {
        this.discount = discount;
    }

    @Column(name = "category_id", nullable = false)
    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    @Column(name = "deleted", nullable = false)
    public int getDeleted() {
        return deleted;
    }

    public void setDeleted(int deleted) {
        this.deleted = deleted;
    }

    @Column(name = "create_time", nullable = false)
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Column(name = "modify_time", nullable = false)
    public Timestamp getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Timestamp modifyTime) {
        this.modifyTime = modifyTime;
    }

    public void setRelated() {
        this.category = ShopCategoryEntity.find.byId(this.categoryId);
    }
}
